#include "Comm.hpp"

int main()
{
    // 创建个命名管道
    Fifo fifo(Path);//匿名对象生命周期一行

    int rfd = open(Path, O_RDONLY);
    if (rfd < 0)
    {
        cerr << "open fail,erro:" << errno << ",errstring" << strerror(errno) << endl;
        return 1;
    }
    cout << "wait message" << endl;
    char buffer[1024];
    while (true)
    {
        ssize_t n = read(rfd, buffer, sizeof(buffer) - 1);
        if (n > 0)
        {
            cout << "client say:" << buffer << endl;
            buffer[n] = 0;
        }
        if (n == 0)
        {
            cout << "client quit,me too" << endl;
            break;
        }
        if (n < 0)
        {
            cerr << "write fail,erro:" << errno << ",errstring" << strerror(errno) << endl;
            break;
        }
    }

    close(rfd);
    return 0;
}